import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/chipGroup/chip_group.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:router/annotation.dart';

@RouterConfig(MiniProgramModePage.pageName)
class MiniProgramModePage extends StatefulWidget {
  static const pageName = '/MiniProgramModePage';

  @override
  _MiniProgramModePageState createState() => _MiniProgramModePageState();
}

class _MiniProgramModePageState extends BaseState<MiniProgramModePage> {
  _MiniProgramModePageState() : super(MiniProgramModePage.pageName);

  final data = [
    _ChipGroupBean('如何布置点餐二维码', [
      ChipData(title: '一座一码', value: 0),
      ChipData(title: '一桌一码', value: 1),
      ChipData(title: '布置在收银台', value: 2),
    ]),
    _ChipGroupBean('顾客扫码后可支持', [
      ChipData(title: '点餐+付款', value: 0),
      ChipData(title: '仅点餐', value: 2),
      ChipData(title: '仅付款', value: 3),
    ]),
    _ChipGroupBean('顾客何时付款', [
      ChipData(title: '先付款后就餐', value: 0),
      ChipData(title: '先就餐后付款', value: 1),
    ]),
    _ChipGroupBean('顾客付款后，订单如何结账', [
      ChipData(title: '订单自动结账', value: 0),
      ChipData(title: '店员手动结账', value: 1),
    ]),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(title: '点餐设置'),
      body: Column(
        children: [
          Expanded(
            child: SingleChildScrollView(
              padding: EdgeInsets.symmetric(horizontal: 30.w),
              child: Column(
                children: data.map((item) => buildRow(item)).toList(),
              ),
            ),
          ),
          FixedBottomBtn(title: '保存'),
        ],
      ),
    );
  }

  Widget buildRow(_ChipGroupBean item) {
    return Container(
      margin: EdgeInsets.only(bottom: 20.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 90.w,
            alignment: Alignment.centerLeft,
            child: Text(item.title, style: TextStyleConstant().normal_1_32),
          ),
          ChipGroup(
            items: item.items,
            value: 1,
            isAverage: true,
          ),
        ],
      ),
    );
  }
}

class _ChipGroupBean {
  String title;
  List<ChipData> items;
  bool isHide;

  _ChipGroupBean(this.title, this.items, {this.isHide = false});
}

class _ChipBean {
  String title;
  bool enabled;

  _ChipBean(this.title, {this.enabled = true});
}
